<?php
/**
 * 在线编辑器-图片上传类
 * @author 邝达峰
 */
class Ke_upload extends BaseAction
{
	/**
	 * 初始化
	 */
	public function _init()
	{
	}

	/**
	 * 默认动作
	 */
	protected function _default()
	{
		if($_SERVER["REQUEST_METHOD"] == "POST"){
			if(strpos($_SERVER['HTTP_REFERER'],'net114') !== 0)
			{
				//上传图片处理
				$uploadPath = 'uploads/editor/'.date("m").'/'.date("d").'/';
				$oImage = new Upload($uploadPath,1024);
				
				$oImage->upFiles();
				$file_url = Func::imageSrcHandle($_REQUEST['imgFile'],'z','auto*auto','1');				
                if($oImage->error){
                    $a = trim(trim($oImage->error));
                    $this->alert($a);
                    exit();
                }

				//限制最大宽度为720
				if (strlen($file_url)>20) {				
						$s = preg_split("/\./", $file_url); array_pop($s);
						$a = preg_split("/_/", array_pop($s));
						array_shift($a); array_pop($a);
						if (count($a)==2) {
							$w=intval($a[0]);
							$h=intval($a[1]);
							if ($w>720&&$h>0) {
								$file_url = Func::imageSrcHandle($_REQUEST['imgFile'],'z','720*auto','1');
							}
						}
						
				}

				//插入图片，关闭层
				echo '<html>';
				echo '<head>';
				echo '<title>Insert Image</title>';
				echo '<meta http-equiv="content-type" content="text/html; charset=utf-8">';
				echo '</head>';
				echo '<body>';
				echo '<script type="text/javascript">';
				echo 'parent.parent.KE.plugin["image"].insert("' . $_POST['id'] . '", "' . $file_url . '","' . $_POST['imgTitle'] . '","' . $_POST['imgWidth'] . '","' . $_POST['imgHeight'] . '","' . $_POST['imgBorder'] . '","' . $_POST['align'] . '");';
				echo '</script>';
				echo '</body>';
				echo '</html>';
				//退出程序
				exit();
			}
		}
		$this->alert('操作有误');
	}
}
?>
